package ercahshu

import "math"

func getMinimumDifference(root *TreeNode) int {
	var preNode *TreeNode
	var dfs func(node *TreeNode)
	ans := math.MaxInt
	dfs = func(node *TreeNode) {
		if node == nil {
			return
		}
		dfs(node.Left)
		if preNode != nil {
			ans = min(ans, node.Val-preNode.Val)
		}
		preNode = node
		dfs(node.Right)
	}
	return ans
}
